/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bytecodes.eaulas.estadisticas;

import java.io.IOException;
import javax.swing.JTable;
import javax.swing.table.TableModel;

/**
 *
 * @author Riki
 */
public class ExportacionListados {

    public ExportacionListados() {
    }

    public static String exportTable(JTable table) throws IOException {
        TableModel model = table.getModel();
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < model.getColumnCount(); i++) {            
            out.append(model.getColumnName(i) + "\t");
        }
        out.append(System.getProperty("line.separator"));

        for (int i = 0; i < model.getRowCount(); i++) {
            for (int j = 0; j < model.getColumnCount(); j++) {
                out.append(model.getValueAt(i, j).toString());
                if(j < model.getColumnCount()-1){        
                out.append(",");
                        out.append("\t");
                }
                
            }
            out.append(System.getProperty("line.separator"));
        }
        
       return out.toString(); 
    }
}
